package com.yanfan.data.controller;

import com.yanfan.common.annotation.Log;
import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.core.page.TableDataInfo;
import com.yanfan.common.enums.BusinessType;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.data.domain.SnmpOid;
import com.yanfan.data.service.ISnmpOidService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * snmp协议OID子表Controller
 *
 * @author kerwincui
 * @date 2024-07-30
 */
@RestController
@RequestMapping("/snmp/oid")
public class SnmpOidController extends BaseController {
    @Autowired
    private ISnmpOidService snmpOidService;

    /**
     * 查询snmp协议OID子表列表
     */
    @PreAuthorize("@ss.hasPermi('snmp:oid:list')")
    @GetMapping("/list")
    public TableDataInfo list(SnmpOid snmpOid) {
        startPage();
        List<SnmpOid> list = snmpOidService.selectSnmpOidList(snmpOid);
        return getDataTable(list);
    }

    /**
     * 导出snmp协议OID子表列表
     */
    @PreAuthorize("@ss.hasPermi('snmp:oid:export')")
    @Log(title = "snmp协议OID子表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SnmpOid snmpOid) {
        List<SnmpOid> list = snmpOidService.selectSnmpOidList(snmpOid);
        ExcelUtil<SnmpOid> util = new ExcelUtil<SnmpOid>(SnmpOid.class);
        util.exportExcel(response, list, "snmp协议OID子表数据");
    }

    /**
     * 获取snmp协议OID子表详细信息
     */
    @PreAuthorize("@ss.hasPermi('snmp:oid:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(snmpOidService.selectSnmpOidById(id));
    }

    /**
     * 新增snmp协议OID子表
     */
    @PreAuthorize("@ss.hasPermi('snmp:oid:add')")
    @Log(title = "snmp协议OID子表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SnmpOid snmpOid) {
        return toAjax(snmpOidService.insertSnmpOid(snmpOid));
    }

    /**
     * 修改snmp协议OID子表
     */
    @PreAuthorize("@ss.hasPermi('snmp:oid:edit')")
    @Log(title = "snmp协议OID子表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SnmpOid snmpOid) {
        return toAjax(snmpOidService.updateSnmpOid(snmpOid));
    }

    /**
     * 删除snmp协议OID子表
     */
    @PreAuthorize("@ss.hasPermi('snmp:oid:remove')")
    @Log(title = "snmp协议OID子表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(snmpOidService.deleteSnmpOidByIds(ids));
    }
}
